/**
 * 
 */
package com.xbang.attendance.web.action.system.product;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.attendance.entity.order.PurchaseOrder;
import com.xbang.attendance.entity.product.Product;
import com.xbang.attendance.entity.product.ProductCategory;
import com.xbang.attendance.entity.system.Region;
import com.xbang.attendance.service.ProductService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.BaseActionSupport;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class Search extends SearchActionSupport {

	private static final Log logger = LogFactory.getLog(Search.class);

	private static final long serialVersionUID = -1120551442020217513L;
	@Autowired
	private ProductService productService;

	private List<Product> products = new ArrayList<Product>();

	private List<ProductCategory> productCategorys = new ArrayList<ProductCategory>();

	public String execute() throws Exception {

		productCategorys = productService.getObjects(ProductCategory.class);

		return "search";
	}

	/**
	 * @return
	 * @throws Exception
	 */
	@Action("/system/product/search/do")
	public String doSearch() throws Exception {
		String hqlSentence = "FROM Product product WHERE 1 = 1 ";
		if (searchComponent.getOrderParameters().isEmpty()){
			searchComponent.addSearchElement("orderBy.product.productCode", "ASC");
		}
		Result result = productService.searchByPage(hqlSentence, searchComponent, page);
		products = result.getItems();
		page = result.getPage();

		return "index";
	}

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}

	public ProductService getProductService() {
		return productService;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public List<ProductCategory> getProductCategorys() {
		return productCategorys;
	}

	public void setProductCategorys(List<ProductCategory> productCategorys) {
		this.productCategorys = productCategorys;
	}

}
